import globalvariable

#通过Python调用C++方法获取K线M1数据范例，Python可根据M1周期生成其他周期数据
def OnTick(marketdata,  strategyname):

    print("M1 K线合约名称 ref(0): " + str(globalvariable.md.GetKline(marketdata.contents.InstrumentID, 0).contents.InstrumentID, encoding="utf-8"))
    print("M1 K线结束时间 ref(0): " + str(globalvariable.md.GetKline(marketdata.contents.InstrumentID, 0).contents.KlineTime))
    print("M1 K线 最高价 ref(0): " + str(globalvariable.md.GetKline(marketdata.contents.InstrumentID, 0).contents.HighestPrice))
    print("M1 K线 最低价 ref(0): " + str(globalvariable.md.GetKline(marketdata.contents.InstrumentID, 0).contents.LowestPrice))
    print("M1 K线 收盘价 ref(0): " + str(globalvariable.md.GetKline(marketdata.contents.InstrumentID, 0).contents.ClosePrice))
    print("M1 K线 成交量 ref(0): " + str(globalvariable.md.GetKline(marketdata.contents.InstrumentID, 0).contents.Volume))
    print("M1 K线 交易日 ref(0): " + str(globalvariable.md.GetKline(marketdata.contents.InstrumentID, 0).contents.TradingDay, encoding="utf-8"))

    print("M1 K线合约名称 ref(1): " + str(globalvariable.md.GetKline(marketdata.contents.InstrumentID, 1).contents.InstrumentID, encoding="utf-8"))
    print("M1 K线结束时间 ref(1): " + str(globalvariable.md.GetKline(marketdata.contents.InstrumentID, 1).contents.KlineTime))
    print("M1 K线 最高价 ref(1): " + str(globalvariable.md.GetKline(marketdata.contents.InstrumentID, 1).contents.HighestPrice))
    print("M1 K线 最低价 ref(1): " + str(globalvariable.md.GetKline(marketdata.contents.InstrumentID, 1).contents.LowestPrice))
    print("M1 K线 收盘价 ref(1): " + str(globalvariable.md.GetKline(marketdata.contents.InstrumentID, 1).contents.ClosePrice))
    print("M1 K线 成交量 ref(1): " + str(globalvariable.md.GetKline(marketdata.contents.InstrumentID, 1).contents.Volume))
    print("M1 K线 交易日 ref(1): " + str(globalvariable.md.GetKline(marketdata.contents.InstrumentID, 1).contents.TradingDay, encoding="utf-8"))

    print("M1 K线合约名称 ref(2): " + str(globalvariable.md.GetKline(marketdata.contents.InstrumentID, 2).contents.InstrumentID, encoding="utf-8"))
    print("M1 K线结束时间 ref(2): " + str(globalvariable.md.GetKline(marketdata.contents.InstrumentID, 2).contents.KlineTime))
    print("M1 K线 最高价 ref(2): " + str(globalvariable.md.GetKline(marketdata.contents.InstrumentID, 2).contents.HighestPrice))
    print("M1 K线 最低价 ref(2): " + str(globalvariable.md.GetKline(marketdata.contents.InstrumentID, 2).contents.LowestPrice))
    print("M1 K线 收盘价 ref(2): " + str(globalvariable.md.GetKline(marketdata.contents.InstrumentID, 2).contents.ClosePrice))
    print("M1 K线 成交量 ref(2): " + str(globalvariable.md.GetKline(marketdata.contents.InstrumentID, 2).contents.Volume))
    print("M1 K线 交易日 ref(2): " + str(globalvariable.md.GetKline(marketdata.contents.InstrumentID, 2).contents.TradingDay, encoding="utf-8"))

    print("M1 K线合约名称 ref(3): " + str(globalvariable.md.GetKline(marketdata.contents.InstrumentID, 3).contents.InstrumentID, encoding="utf-8"))
    print("M1 K线结束时间 ref(3): " + str(globalvariable.md.GetKline(marketdata.contents.InstrumentID, 3).contents.KlineTime))
    print("M1 K线 最高价 ref(3): " + str(globalvariable.md.GetKline(marketdata.contents.InstrumentID, 3).contents.HighestPrice))
    print("M1 K线 最低价 ref(3): " + str(globalvariable.md.GetKline(marketdata.contents.InstrumentID, 3).contents.LowestPrice))
    print("M1 K线 收盘价 ref(3): " + str(globalvariable.md.GetKline(marketdata.contents.InstrumentID, 3).contents.ClosePrice))
    print("M1 K线 成交量 ref(3): " + str(globalvariable.md.GetKline(marketdata.contents.InstrumentID, 3).contents.Volume))
    print("M1 K线 交易日 ref(3): " + str(globalvariable.md.GetKline(marketdata.contents.InstrumentID, 3).contents.TradingDay, encoding="utf-8"))

    print("M1 K线合约名称 ref(4): " + str(globalvariable.md.GetKline(marketdata.contents.InstrumentID, 4).contents.InstrumentID, encoding="utf-8"))
    print("M1 K线结束时间 ref(4): " + str(globalvariable.md.GetKline(marketdata.contents.InstrumentID, 4).contents.KlineTime))
    print("M1 K线 最高价 ref(4): " + str(globalvariable.md.GetKline(marketdata.contents.InstrumentID, 4).contents.HighestPrice))
    print("M1 K线 最低价 ref(4): " + str(globalvariable.md.GetKline(marketdata.contents.InstrumentID, 4).contents.LowestPrice))
    print("M1 K线 收盘价 ref(4): " + str(globalvariable.md.GetKline(marketdata.contents.InstrumentID, 4).contents.ClosePrice))
    print("M1 K线 成交量 ref(4): " + str(globalvariable.md.GetKline(marketdata.contents.InstrumentID, 4).contents.Volume))
    print("M1 K线 交易日 ref(4): " + str(globalvariable.md.GetKline(marketdata.contents.InstrumentID, 4).contents.TradingDay, encoding="utf-8"))